package com.example.singleactivitytemplate.ui.fragment.basicSettings

import android.media.AudioManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.example.singleactivitytemplate.databinding.FragmentBasicSettingBinding
import com.example.singleactivitytemplate.ui.base.BaseFragment


class BasicSettingFragment : BaseFragment<FragmentBasicSettingBinding, BasicSettingViewModel>(),
    View.OnClickListener {
    override fun getViewBindingClass(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): FragmentBasicSettingBinding {
        return FragmentBasicSettingBinding.inflate(inflater, container, false)
    }

    override fun getViewModelClass(): Class<BasicSettingViewModel> {
        return BasicSettingViewModel::class.java
    }

    override fun initData() {

    }

    override fun initOnListener() {
        viewBinding?.btnBrightnessAdd?.setOnClickListener(this)
        viewBinding?.btnBrightnessMinus?.setOnClickListener(this)
        viewBinding?.btnVolumeAdd?.setOnClickListener(this)
        viewBinding?.btnVolumeMinus?.setOnClickListener(this)
    }

    override fun onStart() {

        super.onStart()
    }

    override fun initObserver() {
        mViewModel?.mCurrentBrightness?.observe(this)
        {

            viewBinding?.brightnessProgress?.progress = it.div(2).minus(1)
            viewBinding?.brightnessProgressTv?.text = it.div(2).minus(1).toString() + "%"
        }
        mViewModel?.mCurrentVolume?.observe(this)
        {
            viewBinding?.volumeProgress?.progress = it

        }
    }

    override fun detach() {
    }

    override fun onClick(v: View?) {
        when (v) {
            viewBinding?.btnBrightnessAdd -> {
                mViewModel?.brightnessAdd()
            }
            viewBinding?.btnBrightnessMinus -> {
                mViewModel?.brightnessMinus()
            }
            viewBinding?.btnVolumeAdd -> {
                mViewModel?.volumeAdd()
            }
            viewBinding?.btnVolumeMinus -> {
                mViewModel?.volumeMinus()
            }
        }
    }


}